//
//  SGAuthorView.swift
//  songguo
//
//  Created by 潘传洲 on 16/6/16.
//  Copyright © 2016年 pcz. All rights reserved.
//

import UIKit

private let bottomViewHeight : CGFloat = 90

class SGAuthorView: UIView {

    lazy private var topView : UIView = {
        let height : CGFloat = 40
        let topView = UIView()
        topView.frame = CGRect(x: 0, y: 0, width: screenWidth, height: height)
        
        // 左侧标题
        let textLabel = UILabel()
        textLabel.text = "推荐生活家"
        textLabel.textColor = UIColor.color(99, g: 99, b: 99)
        textLabel.font = UIFont.systemFontOfSize(12)
        textLabel.sizeToFit()
        textLabel.x = 5
        textLabel.height = height
        topView.addSubview(textLabel)
        
        // 右侧标题
        let changeBtn = UIButton()
        changeBtn.addTarget(self, action: #selector(change), forControlEvents: .TouchUpInside)
        changeBtn.titleLabel?.font = UIFont.systemFontOfSize(14)
        changeBtn.setTitle("换一换", forState: .Normal)
        changeBtn.setImage(UIImage(named: "refresh_16x16_"), forState: .Normal)
        changeBtn.setTitleColor(globalColor, forState: .Normal)
        changeBtn.sizeToFit()
        changeBtn.imageEdgeInsets = UIEdgeInsets(top: 0, left: 42, bottom: 0, right: 0)
        changeBtn.titleEdgeInsets = UIEdgeInsets(top: 0, left: -40, bottom: 0, right: 0)
        changeBtn.x = screenWidth - changeBtn.width - 10
        changeBtn.height = height
        topView.addSubview(changeBtn)
        
        return topView
    }()

    lazy private var bottomView : UIView = {
        let bottomView = UIView()
        bottomView.frame = CGRect(x: 0, y: CGRectGetMaxY(self.topView.frame), width: screenWidth, height: bottomViewHeight)
        
        for i in 0..<4{
            let maxColNumber = 4
            let row = i % maxColNumber
            let col = i / maxColNumber
            let width : CGFloat = screenWidth / CGFloat(maxColNumber)
            let height : CGFloat = bottomViewHeight
            let x : CGFloat = CGFloat(row) * width;
            let y : CGFloat = CGFloat(col) * height;
            let view = UIView(frame : CGRect(x: x, y: y, width: width, height: height))
            view.backgroundColor = UIColor().randomColor
//            let btn = SGAutoButton()
////            btn.setImage(UIImage(named: iconArray[i]), forState: .Normal)
////            btn.setTitle(nameArray[i], forState: .Normal)
//            btn.sizeToFit()
//            btn.setTitleColor(globalColor, forState: .Normal)
//            btn.center = CGPoint(x: height / 2, y: width / 2)
//            view.addSubview(btn)
            bottomView.addSubview(view)
        }
        return bottomView
    }()
    
    
    func change() {
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.addSubview(topView)
        self.addSubview(bottomView)
        self.backgroundColor = UIColor.whiteColor()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
